package com.example.mall.service.impl;

import com.example.mall.dao.UserDAO;
import com.example.mall.entity.User;
import com.example.mall.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    private UserDAO userDAO;

    @Autowired
    public UserServiceImpl(UserDAO userDAO) {
        this.userDAO = userDAO;
    }

    @Override
    public List<User> selectAll() {
        return userDAO.selectAll();
    }

    @Override
    public User selectOneById(Integer id) {
        return userDAO.selectOneById(id);
    }

    @Override
    public User selectOneByUsername(String username) {
        return userDAO.selectOneByUsername(username);
    }

    /**
     * 分页查询
     *  - 后台管理需要查询到所有状态的用户
     * @param page
     * @param pageSize
     * @param user 包含需要模糊查询的字段, 为null时则不走模糊查询。
     * @return
     */
    @Override
    public List<User> query(Integer page, Integer pageSize, User user) {
        return null;
    }

    @Override
    public void save(User user) {
        userDAO.save(user);
    }

    @Override
    public void delete(Integer id) {
        userDAO.delete(id);
    }

    @Override
    public void update(User user) {
        userDAO.update(user);
    }
}
